#ifndef _OSIP_MT_H_
#define _OSIP_MT_H_

#include "internal.h"


class osip_mutex
{
public:
	osip_mutex(void);

	virtual ~osip_mutex(void);

	virtual void enter_mutex();

	virtual void leave_mutex();

protected:
#ifndef WIN32
	pthread_mutex_t		m_event_mutex;
#else
	CRITICAL_SECTION	m_event_mutex;
#endif // WIN32
};

class osip_sem
{
public:
	osip_sem();

	virtual ~osip_sem();

	virtual	void sem_signal();

	virtual bool sem_objwait();

	virtual bool sem_timewait(int msec);
private:
#ifdef WIN32
	HANDLE _sem;	
#else
	sem_t _sem;	
#endif
};

class osip_event : public osip_mutex
{
public:
	osip_event(void);

	virtual ~osip_event(void);

	virtual	void event_signal();

	virtual bool event_objwait();

	virtual bool event_timewait(int msec);
protected:

#ifndef WIN32
	bool				m_hasnal;
	pthread_cond_t		m_event_cond;
#else
	HANDLE				m_event_cond;
#endif // WIN32
};

class CAutoMutex
{
public:
	CAutoMutex(osip_mutex* cirt);
	CAutoMutex(osip_mutex& cirt);
	virtual ~CAutoMutex();
private:
	osip_mutex& m_stCS;
};

class osip_thread
{
public:
	osip_thread();

	virtual void Run();

	virtual ~osip_thread();
public:
	virtual void End();

	virtual void Join();

	virtual bool IsRun();

	virtual int  Start();

#ifndef WIN32
	virtual int	Start(void* (*ThreadFun)(void*), void* lpParam);
#else
	virtual int	Start(_beginthreadex_proc_type ThreadFun, void* lpParam);
#endif // WIN32
protected:
	bool	m_bThreadEnd;
#ifndef WIN32
	pthread_t	 m_hThread;
	static void* ThreadProc(void* pParam);
#else
	HANDLE		 m_hThread;
	static unsigned WINAPI ThreadProc(void* pParam);
#endif // WIN32
};

#endif 
